version 15
set more off
global maindir "/home/`c(username)'/Dropbox/Research/Nazis"

* to get nicer tables immediately
global texcode "prehead(\begin{table}`=char(13)'`=char(9)'\centering`=char(13)'`=char(9)'\caption{@title}`=char(13)'`=char(9)'\label{}`=char(13)'`=char(9)'\footnotesize`=char(13)'`=char(9)'\begin{threeparttable}`=char(13)'`=char(9)'`=char(9)'\begin{tabular}{l*{@M}{S}}`=char(13)'\toprule) posthead(\cmidrule(lr{.75em}){2-@M}) prefoot(\cmidrule(lr{.75em}){2-@M}) postfoot(\bottomrule`=char(13)'`=char(9)'`=char(9)'\end{tabular}`=char(13)'`=char(9)'\begin{tablenotes}[para,flushleft]`=char(13)'`=char(9)'`=char(9)'\item Note: @note@starlegend.`=char(13)'`=char(9)'\end{tablenotes}`=char(13)'`=char(9)'\end{threeparttable}`=char(13)'\end{table}) substitute(_ :)"


// TABLE 1 descriptive statistics

* read data
use "$maindir/Data/master.dta", clear
eststo clear

* fix sample to main estimation sample
xi: xtivreg2 infoaratel1lebgeb i.jahr (subdocmel1psh = emigration), first fe cluster(id)
keep if e(sample)

* detailed descriptive statistics, full sample, no differentiation, using tabstat
global dlist "infoaratel1lebgeb mdarmu1jratel1lebgeboa angeblsfruehratel1lebgeboa stillbadjoaratel1geb masernl1psh scharlachl1psh diphteriel1psh influenzaohnel1psh bronchitisl1psh lungel1psh pop pop1k subdocmel1psh emigration jewdocl1psh c33juden1k c33judenquote jquote1933"
tabstat $dlist, stats(median mean sd min max n sum cv) save
tabstatmat output
matrix output = output'
matrix list output
outtable using "$maindir/Results/Tables/desc_full", mat(output) center replace ///
nobox f(%12.3fc %12.3fc %12.3fc %12.3fc %12.3fc %12.0fc %12.3fc %12.3fc) // label




//=============================== parallel trend ===============================

// FIGURE 3

/* global maindir "/home/helge/Dropbox/Nazis" */
use "$maindir/Data/master.dta", clear
xi: xtivreg2 infoaratel1geb i.jahr (subdocmel1psh = emigration), first fe cluster(id)
keep if e(sample)

generate totalemigrationzero = (totalemigration == 0)

generate totalemigrationweight = totalemigration
replace  totalemigrationweight = 1 if totalemigration == 0

generate emigrationweight = emigration
replace  emigrationweight = 1 if emigration == 0

binscatter subdocmel1psh jahr [aweight=emigrationweight], by(totalemigrationzero) ///
   line(connect) graphregion(color(white)) bgcolor(white) name(t1, replace) ///
   title("(a) Registered physicians", margin(0 0 5 0)) ///
   xtitle("Year", height(5)) xline(1932) ///
   ytitle("Physicians", height(5)) ylab(0.4(0.4)2.0, nogrid) /// ylab(0.2(0.4)2.2, nogrid) /// ylab(0.6(0.2)1.6, nogrid) /// ylab(0.5(0.5)2.0, nogrid) /// ylab(0(0.5)2.5, nogrid) ///
   legend(order(1 "No physician emigration" 2 "Any physician emigration") rows(1) region(color(white)))
gr_edit .plotregion1.plot2.style.editstyle line(pattern(shortdash)) editcopy
binscatter lntodu1joa jahr [aweight=emigrationweight], by(totalemigrationzero) ///
   line(connect) graphregion(color(white)) bgcolor(white) name(t2, replace) ///
   title("(b) Infant deaths", margin(0 0 5 0)) ///
   xtitle("Year", height(5)) xline(1932) ///
   ytitle("Infant deaths (ln)", height(5)) ylab(0(2)10, nogrid) ///
   legend(order(1 "No physician emigration" 2 "Any physician emigration") rows(1) region(color(white)))
gr_edit .plotregion1.plot2.style.editstyle line(pattern(shortdash)) editcopy
grc1leg t1 t2, graphregion(color(white)) name(t, replace)
graph save "$maindir/Results/Graphs/trendcombineln.gph", replace
graph export "$maindir/Results/Graphs/trendcombineln.eps", replace logo(off) fontface(helvetica)
!/usr/bin/epstopdf "$maindir/Results/Graphs/trendcombineln.eps" --outfile="$maindir/Results/Graphs/trendcombineln.pdf"
writepsfrag "$maindir/Results/Graphs/trendcombineln.eps" using "$maindir/Results/Graphs/trendcombineln.tex", replace textsize("\footnotesize")



//================ long time series infant mortality in germany ================

// FIGURE 1

import delimited using "$maindir/Data/Ärzte/Ärzte.csv", delim(";") clear
tempfile _temp
save `_temp', replace

import delimited using "$maindir/Data/infant_mortality_germany_neu.csv", delim(";") clear
assert geb == lebgeb + todgeb if geb != .
replace geb = lebgeb + todgeb if geb == . & lebgeb != . & todgeb != .
sort jahr

drop if tag == "" & inrange(jahr,1946,1955)
merge 1:1 jahr using `_temp', keep(match master)
drop _merge

preserve
drop if jahr > 2010
graph twoway ///
    (line infrate jahr, lcolor(gs5) cmissing(n))     ///
    (line doc_1000_pop jahr if jahr < 1942, msize(*0.5) lc(gs10) lp(dash) yaxis(2))     ///
    (line doc_1000_pop jahr if jahr > 1945, msize(*0.5) lc(gs10) lp(dash) yaxis(2))     ///
    , graphregion(color(white)) bgcolor(white)   ///
    xtitle("Year") ///
    ytitle("Infant mortality" "(per 1,000 live births)", height(10))  ylab(,nogrid) ///
    ytitle("Physicians" "(per 1,000 of population)", axis(2) height(10)) ylab(,nogrid) ///
    legend(order(1 "Infant mortality" 2 "Physician density") symxsize(5) region(color(white))) ///
    xlab(1820(40)2020) xmtick(1840 1880 1920 1960 2000) ///
    aspectratio(0.75)
graph save "$maindir/Results/Graphs/infphyscombinedlong.gph", replace
graph export "$maindir/Results/Graphs/infphyscombinedlong.eps", replace logo(off) fontface(helvetica)
!/usr/bin/epstopdf "$maindir/Results/Graphs/infphyscombinedlong.eps" --outfile="$maindir/Results/Graphs/infphyscombinedlong.pdf"
writepsfrag "$maindir/Results/Graphs/infphyscombinedlong.eps" using "$maindir/Results/Graphs/infphyscombinedlong.tex", replace textsize("\footnotesize")
restore


//=================== a map of the distribution of jewish pop ==================

// FIGURE 2

// from actual district census data

use "$maindir/Data/Geodata/Map/map.dta", clear

/* shp2dta using "$maindir/Data/Geodata/Map/1930_gesamt", replace /// */
/*     database(drdb) coordinates(drcd) genid(id) // gencentroids(cen) */

* Create maps
use "$maindir/Data/Geodata/Map/drdb.dta", clear

* Merge with map dataset
merge 1:1 KeyID using "$maindir/Data/Geodata/Map/map.dta"
drop _merge schluessel lae_code

spmap judenquote using "$maindir/Data/Geodata/Map/drcd.dta", id(id) ///
    line(data("$maindir/Data/Geodata/Map/drlcd.dta") size(*.3)) ///
    clmethod(custom) clbreaks(0 0.2 0.5 1 2 4) ///
    legstyle(2) legend(position(5)) ///
    legtitle("Jewish pop." "share (%)" " ") ///
    fcolor(Greens) ocolor(gs11 gs11 gs11 gs11 gs11 gs11) ///
    osize(*0.01 *0.01 *0.01 *0.01 *0.01 *0.01)
graph export "$maindir/Results/Graphs/mapclb.eps", replace logo(off)
writepsfrag "$maindir/Results/Graphs/mapclb.eps" using "$maindir/Results/Graphs/mapclb.tex", replace textsize("\footnotesize")
!/usr/bin/epstopdf "$maindir/Results/Graphs/mapclb.eps" --outfile="$maindir/Results/Graphs/mapclb.pdf"


